package max.ta.data.plot;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import max.ta.download.ResourceDownloader;
import max.ta.timer.TaskBase;
import max.ta.timer.TimerEngine;
import max.ta.util.file.FileHelper;

import org.apache.log4j.Logger;


public class TimerEngineTest {

    private static final Logger logger = Logger.getLogger(TimerEngineTest.class);
    // -----------------------------------------------------------------------------
    private static final ResourceDownloader DOWNLOADER = new ResourceDownloader();
    private static final String SYMBOL = "IBM";
    private static final TimerEngine TIMER_ENGINE = new TimerEngine();

    // -----------------------------------------------------------------------------
    public static void main(String[] args) {
	TIMER_ENGINE.execute(new TaskBase("TIMER-1") {

	    @Override
	    public void run() {
		try {
		    URL url = new URL("http://download.finance.yahoo.com/d/quotes.csv?s=" + SYMBOL + "&f=nsl1d1c1ohgv");
		    File file = DOWNLOADER.downloadFile(url, SYMBOL);
		    logger.debug(FileHelper.read(file));
		} catch (MalformedURLException e) {
		    e.printStackTrace();
		} catch (IOException e) {
		    e.printStackTrace();
		}
	    }
	});
    }




}
